package br.com.utfpr.menu;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;

public class CadastroActivity extends Activity {
	
	private EditText insere_nome;
	private EditText insere_endereco;
	private EditText insere_rg;
	private PessoaController pessoaController;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cadastro);     
        insere_nome = (EditText) findViewById(R.id.insere_nome);
        insere_endereco = (EditText) findViewById(R.id.insere_endereco);
        insere_rg = (EditText) findViewById(R.id.insere_rg);
        pessoaController = new PessoaController((Context)this);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.menu_cadastro, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	Intent intent;
        switch (item.getItemId()) {
	        case R.id.cadastro_salvar:
	        	Pessoa pessoa = new Pessoa(insere_nome.getText().toString(),insere_endereco.getText().toString(), insere_rg.getText().toString(), 0);
				pessoaController.cadastrar(pessoa);
	        break;
        	case R.id.cadastro_consultar:
            	intent = new Intent(this, ConsultaActivity.class);
            	startActivity(intent);
            break;
            case R.id.cadastro_voltar:
            	startActivity(new Intent(this,MainActivity.class));
            break;
        }
        return true;
    }

}
